import request from '@/utils/request'
import {
  getCodeModel,
  loginModel,
  Login,
  RefreshToken,
  userInfoModel
} from '../model/userModel'
// 图形验证码获取
export function getCode() {
  return request<getCodeModel>({
    url: '/login',
    method: 'get',
    noToken: true
  })
}
//登录
export function login(data: Login) {
  return request<loginModel>({
    url: '/auth/login',
    method: 'post',
    noToken: true,
    data
  })
}
//获取用户信息
export function getUserInfoApi(data: { id: number }) {
  return request<userInfoModel>({
    url: '/auth/userInfo',
    method: 'post',
    data
  })
}
//刷新token
export function refreshToken(data: RefreshToken) {
  return request<loginModel>({
    url: 'user/login/refreshToken',
    method: 'post',
    noToken: true,
    data
  })
}
//退出
export function logout(data: RefreshToken) {
  return request<null>({
    url: 'user/login/logout',
    method: 'post',
    data
  })
}
//测试token用接口
export function messages(cancelName: string) {
  return request({
    url: '/service/messages',
    method: 'get',
    cancelName: cancelName
  })
}

// 获取用户列表
export function userPageApi(data) {
  return request({
    url: '/auth/pages',
    method: 'post',
    data
  })
}

// 新增用户
export function addUserApi(data) {
  return request({
    url: '/auth/register',
    method: 'post',
    data
  })
}

// 修改用户
export function editUserApi(data) {
  return request({
    url: '/auth/edit',
    method: 'post',
    data
  })
}

// 删除用户
export function delUserApi(data) {
  return request({
    url: '/auth/delete',
    method: 'post',
    data
  })
}

// 根据用户Id获取机构信息
export function orgAllByOrgTypeApi() {
  return request({
    url: '/user/user/get/orgAllByOrgType',
    method: 'post'
  })
}

// 获取用户的全部角色
export function userRoleApi(data) {
  return request({
    url: '/role/getAllRole',
    method: 'post',
    data
  })
}

// 修改用户角色
export function editUserRoleApi(data) {
  return request({
    url: '/role/addUserByCode',
    method: 'post',
    data
  })
}

// 修改用户密码
export function editUserPasswordApi(data) {
  return request({
    url: '/auth/editPassword',
    method: 'post',
    data
  })
}

// 修改登录用户密码
export function editLoginUserPasswordApi(data) {
  return request({
    url: '/user/user/edit/self/password',
    method: 'post',
    data
  })
}
// 修改登录用户信息
export function editLoginUserSelfApi(data) {
  return request({
    url: '/user/user/edit/self',
    method: 'post',
    data
  })
}
// 修改登录用户信息
export function iamLogin(data) {
  return request({
    url: '/login/iamLogin',
    method: 'post',
    noToken: true,
    data
  })
}
